﻿Public Class frmCustomerDetail

#Region "Method"

#Region "Overrides"

    ''' <summary>
    ''' Sub đưa dữ liệu hiển thị trên control
    ''' </summary>
    ''' <remarks>Nguyễn Huy Thường added on 24/10/2010</remarks>
    Protected Overrides Sub BindingControl()
        With BusinessObject.dsFMS.Customer
            txtName.DataBindings.Add("Text", bsFMS, .CustomerNameColumn.ColumnName)
            txtEmail.DataBindings.Add("Text", bsFMS, .CustomerEmailColumn.ColumnName)
            txtPhone.DataBindings.Add("Text", bsFMS, .CustomerPhoneColumn.ColumnName)
            txtTaxNumber.DataBindings.Add("Text", bsFMS, .CustomerTaxNumberColumn.ColumnName)
            txtAddress.DataBindings.Add("Text", bsFMS, .CustomerAddressColumn.ColumnName)
            txtDescription.DataBindings.Add("Text", bsFMS, .CustomerDescriptionColumn.ColumnName)
            If ActionMode <> clscommon.ActionMode.Add Then
                cboGender.Value = bsFMS.Current(.CustomerGenderColumn.ColumnName)
                LoadInvoiceList()
            End If
        End With
    End Sub

    ''' <summary>
    ''' Sub xóa binding dữ liệu trên control
    ''' </summary>
    ''' <remarks>Nguyễn Huy Thường added on 24/10/2010</remarks>
    Protected Overrides Sub ClearDataBingding()
        With Me
            .txtName.DataBindings.Clear()
            .txtEmail.DataBindings.Clear()
            .txtPhone.DataBindings.Clear()
            .txtTaxNumber.DataBindings.Clear()
            .txtAddress.DataBindings.Clear()
            .txtDescription.DataBindings.Clear()
        End With
    End Sub

    ''' <summary>
    ''' Sub set thuộc tính cho các control là read only hay không
    ''' </summary>
    ''' <param name="isReadOnly">Ở chế độ read only thì đặt là true và ngược lại</param>
    ''' <remarks>Nguyễn Huy Thường added on 24/10/2010</remarks>
    Protected Overrides Sub SetControlEditable(ByVal isReadOnly As Boolean)
        MyBase.SetControlEditable(isReadOnly)
        With Me
            .txtName.ReadOnly = isReadOnly
            .cboGender.ReadOnly = isReadOnly
            .txtEmail.ReadOnly = isReadOnly
            .txtPhone.ReadOnly = isReadOnly
            .txtTaxNumber.ReadOnly = isReadOnly
            .txtAddress.ReadOnly = isReadOnly
            .txtDescription.ReadOnly = isReadOnly
            If ActionMode = clscommon.ActionMode.Add Then
                cboGender.SelectedIndex = 0
                BusinessObject.dsFMS.Invoice.Clear()
            End If
        End With
    End Sub

    ''' <summary>
    ''' Sub xác định vị trí của bản ghi hiện thời và load lại dữ liệu
    ''' </summary>
    ''' <remarks>Nguyễn Huy Thường added on 24/10/2010</remarks>
    Protected Overrides Sub RefreshData()
        MyBase.RefreshData()
        If Not IsNothing(bsFMS.Current) And ActionMode <> clscommon.ActionMode.Add Then
            cboGender.Value = bsFMS.Current(BusinessObject.dsFMS.Customer.CustomerGenderColumn.ColumnName)
            LoadInvoiceList()
        End If
    End Sub

    ''' <summary>
    ''' Sub đặt giá trị cho các trường trước khi lưu dữ liệu
    ''' </summary>
    ''' <remarks>Nguyễn Huy Thường added on 25/06/2012</remarks>
    Protected Overrides Sub SetDataValue()
        BusinessObject.CurrentRow(BusinessObject.dsFMS.Customer.CustomerGenderColumn.ColumnName) = cboGender.Value
    End Sub
#End Region

    ''' <summary>
    ''' Sub đưa danh sách các hóa đơn khách hàng đã mua lên grdInvoiceList
    ''' </summary>
    ''' <remarks>Nguyễn Huy Thường added on 05/07/2010</remarks>
    Private Sub LoadInvoiceList()
        With BusinessObject
            .dsFMS.Invoice.Clear()
            .GetDataByValue(.dsFMS.Invoice.TableName, .dsFMS.Customer.CustomerIDColumn.ColumnName, bsFMS.Current(.dsFMS.Customer.CustomerIDColumn.ColumnName))
        End With
        With Me
            .grdInvoiceList.DataSource = BusinessObject.dsFMS
            .grdInvoiceList.DataMember = BusinessObject.dsFMS.Invoice.TableName
        End With
    End Sub
#End Region
End Class
